#include <bits/stdc++.h>
using namespace std;
struct cow{
    int w, s;
}a[50005];
bool cmp(cow x, cow y){
    return x.s + x.w < y.s + y.w;
}
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i].w >> a[i].s;
    }
    sort(a + 1, a + n + 1, cmp);
    int ans = 0, maxn = -2e9;
    for (int i = 1; i <= n; i++){
        maxn = max(maxn, ans - a[i].s);
        ans += a[i].w;
    }
    cout << maxn;
    return 0;
}